package zxk.spider.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import javafx.beans.DefaultProperty;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import zxk.spider.domain.MovieEntity;
import zxk.spider.mapper.MovieMapper;
import zxk.spider.service.MovieService;

import java.util.List;

/**
 * @fileName: SpiderController
 * @author: 舟小亢
 * @date: 2022-11-05 11:43
 * @description:
 */
@RestController
@RequestMapping
@RequiredArgsConstructor
public class SpiderController {

    private final MovieService movieService;
    private final MovieMapper movieMapper;

    @GetMapping("/start")
    public String c1() {
        return "爬虫系统启动成功！";
    }

    @GetMapping("/spider")
    public String spider() {
        movieService.spiderMovie();
        return "正在抓取数据";
    }

    @GetMapping("/getMovie")
    public Object getMovie(@RequestParam(defaultValue = "0") int pageNum, @RequestParam(defaultValue = "8") int pageSize) {
        Page<MovieEntity> page = Page.of(pageNum, pageSize);
        QueryWrapper<MovieEntity> wrapper = new QueryWrapper<>();
        Page<MovieEntity> list = movieMapper.selectPage(page, wrapper);
//        List<MovieEntity> records = list.getRecords();
        return list;
    }

}
